package com.qf.service.impl;

import com.qf.bean.Grade2;
import com.qf.bean.Student2;
import com.qf.dao.Grade2Dao;
import com.qf.dao.Student2Dao;
import com.qf.service.Student2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 2019/12/2
 * Administrator
 * springdata1130
 * 面向对象面向君  不负代码不负卿
 */
@Service("stuservice")
public class Student2ServiceImpl  implements Student2Service {

    public List<Student2> getStudentsBygid(int gid) {
        return student2Dao.getStudentsBygid(gid);
    }

    public Student2 findbyid(int sid, String stuname) {
        return student2Dao.findbyid_name(sid,stuname);
    }

    @Autowired
    private Student2Dao student2Dao;
   @Autowired
   private Grade2Dao grade2Dao;

    public Grade2 findbygid(int gid) {
        return grade2Dao.findOne(gid);
    }

    public List<Student2> findbygid2(int gid) {
        return student2Dao.findByGrade2_Gid(gid);
    }

    public Student2 findbysid(int sid) {
        return student2Dao.findOne(sid);
    }

    @Transactional
    public int insert(Grade2 grade2, Student2 student2) {
        try {
            //1.新增年级
            Grade2 grade = grade2Dao.save(grade2);
            //2.新增学生
            student2.setGrade2(grade);
            student2Dao.save(student2);
            //3.返回结果
        } catch (Exception e) {
            e.printStackTrace();
            return  0;
        }

        return 1;
    }
}
